package com.hnevc.newapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.hnevc.newapplication.adapter.MyAdapter;

public class MainActivity extends AppCompatActivity {


    private String[] nameArray;
    private String[] desArray;
    private String[] priceArray;
    private ListView goodsList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
        initEvent();
    }

    private void initView() {
        goodsList = findViewById(R.id.goods_listview);
    }

    private void initData() {
        nameArray = new String[]{"猪肉","牛肉","羊肉","鱼","虾"};
        desArray = new String[]{"土猪肉","黄牛肉","黑山羊","草鱼","基围虾"};
        priceArray = new String[]{"13.00","18.00","32.00","14.00","30.00"};
        goodsList.setAdapter(new MyAdapter(MainActivity.this,nameArray,desArray,priceArray));
    }

    private void initEvent() {
        goodsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(MainActivity.this,DetailActivity.class);
                intent.putExtra("name",nameArray[position]);
                intent.putExtra("des",desArray[position]);
                intent.putExtra("price",priceArray[position]);
                startActivity(intent);
            }
        });
    }
}